<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 100px;
            height: 100px;
            background: red;
            position: absolute;
            left: 0px;
            top: 0px
        }
    </style>
</head>

<body>
    <div class="box"></div>
    <script>
        // 拖拽
        var boxEle = document.querySelector(".box");
        boxEle.onmousedown = function (e) {
            var x = e.clientX - this.offsetLeft;
            var y = e.clientY - this.offsetTop;
            this.onmousemove = function (e) {
                var xx = e.clientX - x;
                var yy = e.clientY - y;
                this.style.left = xx + "px";
                this.style.top = yy + "px"
            }
        }

        boxEle.onmouseup = function(){
            // 当鼠标抬起的时候 那么 把 onmousemove事件绑定解除
            // 解绑事件。
            this.onmousemove = null;
        }



        // document.querySelector(".box").onclick = function(){
        //     console.log(123);
        // }

        // document.querySelector(".box").onclick = null;

        // var a = 10;
        // var a = null
        // console.log(a);


    </script>
</body>

</html>